package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.api.db.BlackListApi;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageResult queryBlacklist(Long userId, Integer page, Integer pagesize) {

        Page<UserInfo> page1 = new Page<>(page,pagesize);
        IPage<UserInfo> iPage = blackListMapper.queryBlacklist(page1,userId);
        return new PageResult(page,pagesize,(int)iPage.getTotal(),iPage.getRecords());  //Integer page,Integer pagesize,int counts,List list
    }

    @Override
    public void deleteBlacklist(Long userId, Long blackUserId) {
//        delete from tb_black_list where black_user_id=#{blackUserId} and user_id=#{userId}
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BlackList::getBlackUserId,blackUserId);
        queryWrapper.lambda().eq(BlackList::getUserId,userId);
        blackListMapper.delete(queryWrapper);
    }

}
